<?php
MYTCONN();
	mn_field('hidden','ED','cpl_Selected','','','','','');
echo '<div id="Proc_Totalizer" class="Box">Numero de Remessas: ';
 		mn_field('hidden','ED','POOL','','','','','');
		mn_field('hidden','ED','Ed_PID','','','','','');
		 mn_field('text','ED','SumCard','0','4','4','','" readonly="');
		 echo ' Total Selecionado: ';
	 	mn_field('text','ED','SumEnviado','0.00','8','8','','" readonly="');
		echo ' | ';
		 mn_field('button','ED','prc_add','Associar a processo','','','','" onclick="
		if (document.MQuery.POOL.value != \'\') {
		 	targetwindow(\'Processos Activos\',\'PBC_ProcessBox\',500,400);
			document.MQuery.action=\'_response/call.php?get=Compliance/prc_box\';
			subform(\'MQuery\',\'PBC_ProcessBox\');
		} else {
		alert(\'Nada para associar.\');
		}');
		 echo '</div>
<table width="100%"  border="0" cellpadding="2" cellspacing="0" bordercolor="#666666">
	   <tr bgcolor="#CCCCCC" height="28">
        <td>'; mn_field('checkbox','ED','checkALL','','','','','" onclick="FormGridCheckAll(\'MQuery\');'); echo '</td>
        <td width="8%">Movimento</td>
        <td>Referencia</td>
        <td>Data</td>
        <td>Valor</td>
        <td>Pago</td>
        <td>Taxa</td>
        <td>Estado</td>
      </tr>';
        $GO = array(0);
      if($_POST['CliNumero']>0){
	$GO = $GLOBALS['MYT']->db_array("
	SELECT
		amp_ID AS O_ID,
		amp_Description COL1,
		amp_Time AS COL2,
		name AS COL3,
		'T_PBC' AS COL4,
		CONCAT('Total:',amp_total,' #:',amp_quant) AS COL5,
		amp_Status AS COL6
  	FROM hd_amlprocess
		INNER JOIN  systemoffice.main_users ON ref = amp_User
		WHERE amp_Client = {$_POST['CliNumero']} AND amp_Status != 5
	UNION
	SELECT
		FraID AS O_ID,
		CONCAT(FraOrigen0,'-',LPAD(FraReferenciaAg,6,0)) AS COL1,
		FraFecha AS COL2,
		ROUND(FraEnviado+FraCargo,2) AS COL3,
		ROUND(FraCargo,2) AS COL4,
		ROUND(FraARecibir,2) COL5,
		sg_Abreviatura AS COL6
	FROM facturas
		INNER JOIN hd_statusfacturas ON FraStatus = sg_ID
	  	WHERE FraCliNumero = {$_POST['CliNumero']}
		AND FraID NOT IN (SELECT frp_FraID FROM facturas_pbc
				INNER JOIN hd_amlprocess ON frp_PbcID = amp_ID WHERE amp_Client = FraCliNumero AND amp_Status != 5)
		AND FraStatus NOT IN (1,9,10)
		ORDER BY COL6,COL2");
      }
$TAmount = 0;
	$gg = 0;
  for($g = 1; $g <= $GO[0]; $g++) {
  	if ($GO[$g]['COL4'] != 'T_PBC') {
	  	$gg++;
  $TAmount = $TAmount+$GO[$g]['COL3'];
echo '<tr bgcolor="'.gridlines($g).'" height="20">
        <td NOWRAP>';
		mn_field('checkbox','ED','check',$GO[$g]['O_ID'],'','','','" onclick="FormGridCheck(\'MQuery\',\''.($gg-1).'\');');
		mn_field('hidden','ED','In',$GO[$g]['COL3'],'','','',''); echo '</td>
        <td NOWRAP>'.$GO[$g]['O_ID'].'</td>
        <td NOWRAP>'.$GO[$g]['COL1'].'</td>
        <td NOWRAP>'.$GO[$g]['COL2'].'</td>
        <td NOWRAP>'.$GO[$g]['COL3'].'</td>
        <td NOWRAP>'.$GO[$g]['COL5'].'</td>
        <td NOWRAP>'.$GO[$g]['COL4'].'</td>
        <td NOWRAP>'.$GO[$g]['COL6'].'</td>
      </tr>';
	  } else {
echo '<tr bgcolor="#FFFEEE" height="28">
        <td><img id="ico'.$GO[$g]['O_ID'].'" src="_response/bin.php?get=Objects/Tree/plus.gif"
        onclick="gridtoggle('.$GO[$g]['O_ID'].',\'_response/call.php?get=Compliance/pbcproc&AMPID='.$GO[$g]['O_ID'].'\');"></td>
		<td colspan="7">PROCESSO DE PBC N.'.$GO[$g]['O_ID'].' | '.$GO[$g]['COL1'].' | '.$GO[$g]['COL2'].' | '.$GO[$g]['COL3'].' | '.$GO[$g]['COL6'].' ';
		mn_field('button','ED','amp_Edit','Editar Processo','','','','SUBMIT" onclick="
			document.MQuery.Ed_PID.value='.$GO[$g]['O_ID'].';
			targetwindow(\'Detalhes do Processo '.$GO[$g]['O_ID'].'\',\'PBC_ProcessBox\',500,400);
			document.MQuery.action=\'_response/call.php?get=Compliance/prc_edbox\';
			subform(\'MQuery\',\'PBC_ProcessBox\');');
        echo '<div id="row'.$GO[$g]['O_ID'].'"></div></td>
      </tr>';
	  }
	}
echo '
<tr>
        <td colspan="10"><hr width="100%"></td>
  </tr>
<tr>
        <td NOWRAP>Total</td>
        <td NOWRAP align="right"></td>
        <td NOWRAP align="right"></td>
        <td NOWRAP align="right"></td>
        <td NOWRAP align="right"></td>
        <td NOWRAP align="right"></td>
        <td NOWRAP align="right">'.$TAmount.'</td>
  </tr>
</table>'; ?>
<div id="ok"></div>
<script charset="utf-8" type="text/javascript">
Ext.onReady(function(){
    var xg = Ext.grid;

    // shared reader
    var reader = new Ext.data.ArrayReader({}, [
       {name: 'company'},
       {name: 'price', type: 'float'},
       {name: 'change', type: 'float'},
       {name: 'pctChange', type: 'float'},
       {name: 'lastChange', type: 'date', dateFormat: 'n/j h:ia'},
       {name: 'desc'}
    ]);

    // row expander
    var expander = new xg.RowExpander({
        tpl : new Ext.Template(
            '<p><b>Company:</b> {company}<br>',
            '<p><b>Summary:</b> {desc}</p>'
        )
    });

    var grid1 = new xg.Grid3({
        ds: new Ext.data.Store({
            reader: reader,
            data: xg.dummyData
        }),
        cm: new xg.ColumnModel([
            expander,
            {id:'company',header: "Company", width: 40, sortable: true, dataIndex: 'company'},
            {header: "Price", width: 20, sortable: true, renderer: Ext.util.Format.usMoney, dataIndex: 'price'},
            {header: "Change", width: 20, sortable: true, dataIndex: 'change'},
            {header: "% Change", width: 20, sortable: true, dataIndex: 'pctChange'},
            {header: "Last Updated", width: 20, sortable: true, renderer: Ext.util.Format.dateRenderer('m/d/Y'), dataIndex: 'lastChange'}
        ]),
        viewConfig: {
            forceFit:true
        },
        width: 600,
        height: 300,
        expander: expander,
        collapsible: true,
        animCollapse: false,
        title: 'Expander Rows, Collapse and Force Fit',
        iconCls: 'icon-grid',
        renderTo: 'ok'
    });
});
// Array data for the grids
Ext.grid.dummyData = [
    ['3m Co',71.72,0.02,0.03,'9/1 12:00am']
];

// add in some dummy descriptions
for(var i = 0; i < Ext.grid.dummyData.length; i++){
    Ext.grid.dummyData[i].push('');
}</script>